package component.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

open class BaseViewModel<T> : ViewModel() {

  /**
   * 处理事件
   */
  open fun handleIntent(intent: T){}

  /**
   * 扩展方法，将 LiveData 转换为 MutableLiveData
   */
  @JvmSynthetic
  protected fun <K> LiveData<K>.mutable(): MutableLiveData<K> {
    return this as MutableLiveData<K>
  }

  /**
   * 扩展方法，将 MutableLiveData 转换为 LiveData
   */
  protected fun <K> MutableLiveData<K>.immutable(): LiveData<K> {
    return this
  }
}